home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Prefs / New / Copy_of_ModeProPrefs.cold < prev    next >
Text File  |  1996-06-12  |  39KB  |  1,467 lines

  1. #include "MPP.h"
  2.  
  3. // need to refresh Color display
  4.  
  5. #define MPVER  "4.6"
  6. #define VER 4
  7. #define REV 6
  8.  
  9.  
  10. void FixScreenModeNames(void);
  11.  
  12. BOOL MyScreen;
  13.  
  14. UBYTE   Version[]   ="$VER: ModeProPrefs "MPVER" "__AMIGADATE__;
  15. UBYTE   ModePro[]   ="ModeProPrefs "MPVER;
  16. UBYTE   AboutText[]="ModePro\n"
  17.                      "©1994-1995 by Michael Rivers\n"
  18.                      "  DonationWare (see Docs)\n\n"
  19.                      "%s\n"
  20.                      "%s\n"
  21.                      "  Internet:\n"
  22.                      "    mrivers@tbag.tscs.com\n"
  23.                      "  Mail:\n"
  24.                      "    Michael Rivers\n"
  25.                      "    4302 Wisconsin Court\n"
  26.                      "    Tampa, FL, USA, 33616";
  27.  
  28.  
  29. extern struct TextArea ColorDisp, PenNameDisp, FontDisp;
  30.  
  31. UBYTE EnvFile[]   ="ENV:ModePro.pref",
  32.       EnvArcFile[]="ENVARC:ModePro.pref";
  33.  
  34. ULONG ActivateStrGad=0;
  35. struct List PenList;
  36. LONG ActivePen=0;
  37. extern UBYTE PenNameGad[];
  38. struct PenNode pennode[DRIPENS];
  39. UWORD NumDriPens;
  40. UWORD defaultpens[]=
  41. {
  42.   0,1,1,2,1,3,1,0,2,1,2,1
  43. };
  44. float XScale=1.0,
  45.       YScale=1.0;
  46. extern STRPTR MiscText[];
  47. extern struct Hook StrHook;
  48. extern struct Hook PenLVHook;
  49. extern struct NewGadget nglist[];
  50. extern ULONG gtype[];
  51. extern ULONG gtags[];
  52. extern struct BevelBox BBox[];
  53. extern UBYTE PenNames[DRIPENS][32];
  54. extern UWORD PenNumbers[];
  55. extern struct GUI_String GText[];
  56. extern WORD PenNameLength[],
  57.             BevelBoxes,
  58.             Gadgets;
  59. struct TextAttr *TAttr, User;
  60. struct Menu *MenuStrip;
  61. extern struct   NewMenu nm[];      
  62. struct TextAttr Topaz8 = { "topaz.font",8,0,0};
  63.  
  64. WORD LeftEdge,TopEdge; 
  65.  
  66. struct FontRequester *FontReq;
  67. struct FileRequester *FileReq=NULL;
  68. struct ScreenModeRequester *ScrReq;
  69.  
  70. APTR VI=0;
  71. extern struct Gadget *gadlist[];
  72. struct Gadget   *glist=0;
  73. struct Screen   *Scr=0;
  74. struct Window   *Win=0;
  75. struct DrawInfo *DrawInfo;
  76.  
  77. BOOL    V39;
  78.  
  79. UBYTE   filename[513];
  80.  
  81. LONG   LVActive=0,NodeCnt=0;
  82.  
  83. ULONG  ArgEdit,ArgUse,ArgSave;
  84. STRPTR ArgFrom,ArgPubscreen;
  85. UBYTE  *UserFontName;
  86. LONG   UserFontSize;
  87.  
  88. UBYTE *WindowName,
  89.       *WinAdd,
  90.       *Title1=" = <",
  91.       *Title2=">";
  92.  
  93. struct Catalog *Catalog;
  94.  
  95. BOOL ClosePrefs=FALSE;
  96. struct MPSem   *MPSem;
  97. struct MsgPort *PrefsPort,*ReplyPort;
  98.  
  99. struct IntuitionBase *IntuitionBase; 
  100. struct GfxBase       *GfxBase;
  101. struct Library       *AslBase,
  102.                      *CxBase,
  103.                      *DiskfontBase,
  104.                      *GadToolsBase,
  105.                      *IconBase,
  106.                      *IFFParseBase,
  107.                      *LocaleBase,
  108.                      *UtilityBase;
  109.  
  110. struct Libs MP_Libs[]=
  111. {
  112.   (APTR *)&AslBase,      "asl.library",        38,
  113.   (APTR *)&CxBase,       "commodities.library",36,
  114.   (APTR *)&DiskfontBase, "diskfont.library",   36,
  115.   (APTR *)&GadToolsBase, "gadtools.library",   36,
  116.   (APTR *)&GfxBase,      "graphics.library",   36,
  117.   (APTR *)&IconBase,     "icon.library",       36,
  118.   (APTR *)&IFFParseBase, "iffparse.library",   36,
  119.   (APTR *)&IntuitionBase,"intuition.library",  36,
  120. //  (APTR *)&LocaleBase,   "locale.library",     38,
  121.   (APTR *)&UtilityBase,  "utility.library",    36,
  122.   0,0,0
  123. };
  124.  
  125. ULONG ListToCyc[]={1,0,2};
  126. WORD  CurrentList_2=0,
  127.       CurrentList=1;
  128.  
  129.  
  130. void main(int argc, char **argv)
  131. {
  132.   ULONG l;
  133.   struct Screen *ps;
  134.   
  135.   LONG gotsem=0;
  136.  
  137.   if(LocaleBase=OpenLibrary("locale.library",38))
  138.     Catalog=OpenCatalog(NULL,(STRPTR)"modeproprefs.catalog", TAG_DONE);
  139.   else
  140.     Catalog=NULL;
  141.   
  142.   InitStrings();
  143.  
  144.   if(OpenLibs(ModePro,MP_Libs))
  145.   {
  146.     if(ps=LockPubScreen(NULL))
  147.     {
  148.       DrawInfo=GetScreenDrawInfo(ps);
  149.       for(l=0;l<DrawInfo->dri_NumPens && l<NumDriPens;l++)
  150.         defaultpens[l]=DrawInfo->dri_Pens[l];      
  151.       FreeScreenDrawInfo(ps,DrawInfo);
  152.       UnlockPubScreen(NULL,ps);
  153.     }
  154.  
  155.     if(GetArgs(argc,argv))
  156.     {
  157.       if(Scr=GetScreen())
  158.       {
  159.         Forbid();
  160.         MPSem=(struct MPSem *)FindSemaphore((UBYTE *)"ModePro");
  161.         if(MPSem)
  162.           gotsem=AttemptSemaphoreShared(&MPSem->SharedSem);
  163.         Permit();
  164.         
  165.         if(!gotsem)
  166.         {
  167.           EZReq(0,0,ModePro,GetString(MSG_ERR_NOPATCH),GetString(MSG_REQ_OK),0);
  168.         }
  169.         else
  170.         {
  171.           if(AttemptSemaphore(&MPSem->PrefsSem))
  172.           {
  173.             if(MPSem->Version==VER && MPSem->Revision==REV)
  174.             {
  175.               
  176.               if(ArgFrom)
  177.               {
  178.                 //printf("ArgFrom = %s\n",ArgFrom);
  179.                 ObtainSemaphore(&MPSem->ListSem);
  180.                 ObtainSemaphore(&MPSem->NodeSem);
  181.                 FreeAllDefLists(MPSem->PromotionList);
  182.                 PrefLoadFile(ArgFrom);
  183.                 ReleaseSemaphore(&MPSem->NodeSem);
  184.                 ReleaseSemaphore(&MPSem->ListSem);
  185.               }
  186.               
  187.               if(ArgEdit)
  188.               {
  189.                 if(ReplyPort=CreateMsgPort())
  190.                 {
  191.                   if(PrefsPort=CreateMsgPort())
  192.                   {
  193.                     ObtainSemaphore(&MPSem->PortSem);
  194.                     MPSem->PrefsPort=PrefsPort;
  195.                     ReleaseSemaphore(&MPSem->PortSem);
  196.                     
  197.                     gadlist[GD_LIST]=NULL;
  198.           
  199.                     StrHook.h_Entry=ExcludeHook;
  200.                     PenLVHook.h_Entry=PensLVFunc;
  201.                 
  202.                     if(((struct Library *)IntuitionBase)->lib_Version>38)
  203.                     {
  204.                       NumDriPens=12;
  205.                       V39=TRUE;
  206.                     }
  207.                     else
  208.                     {
  209.                       NumDriPens=9;
  210.                       V39=FALSE;
  211.                     }
  212.                     if(WinAdd=WindowName=AllocVec(strlen(MPSem->HotKey)+
  213.                                                   strlen(GetString(MSG_WINDOW_TITLE))+
  214.                                                   strlen(Title1)+
  215.                                                   strlen(Title2)+1,MEMF_CLEAR|MEMF_PUBLIC))
  216.                     {
  217.                       strcat(WindowName,GetString(MSG_WINDOW_TITLE));
  218.                       strcat(WindowName,Title1);
  219.                       strcat(WindowName,MPSem->HotKey);
  220.                       strcat(WindowName,Title2);
  221.                     }
  222.                     else
  223.                       WindowName=ModePro; 
  224.                      
  225.   
  226.                     SetupPenNodes();
  227.       
  228.                     ObtainSemaphoreShared(&MPSem->ListSem);
  229.                     FixScreenModeNames();
  230.                     if(ShowGUI())
  231.                     {
  232.                       struct Process *proc;
  233.                       struct Window *winptr;
  234.                       
  235.                       proc=(struct Process *)FindTask(0);
  236.                       winptr=proc->pr_WindowPtr;
  237.                       proc->pr_WindowPtr=Win;
  238.                       ProcessInput();
  239.                       proc->pr_WindowPtr=winptr;
  240.                       HideGUI();
  241.                     }
  242.                     ReleaseSemaphore(&MPSem->ListSem);
  243.                      
  244.                     FreeVec(WinAdd);
  245.              
  246.                     ObtainSemaphore(&MPSem->PortSem);
  247.                     MPSem->PrefsPort=0;
  248.                     ReleaseSemaphore(&MPSem->PortSem);
  249.         
  250.                     DeleteMsgPort(PrefsPort);
  251.                   }// endif CreateMsgPort(PrefsPort)
  252.                   DeleteMsgPort(ReplyPort);
  253.                 }// if CreateMsgPort(ReplyPort)
  254.               }// endif(ArgEdit)
  255.               else
  256.                 if(ArgSave)
  257.                 {
  258.                   ObtainSemaphore(&MPSem->ListSem);
  259.                   ObtainSemaphore(&MPSem->NodeSem);
  260.                   PrefSaveFile(EnvArcFile);
  261.                   PrefSaveFile(EnvFile);
  262.                   ReleaseSemaphore(&MPSem->NodeSem);            
  263.                   ReleaseSemaphore(&MPSem->ListSem);
  264.                 }
  265.             }
  266.             else
  267.               EZReq(0,0,ModePro,GetString(MSG_ERR_WRONGVERSIONS),MiscText[OK],
  268.                                          MPSem->Version,MPSem->Revision,VER,REV);          
  269.             ReleaseSemaphore(&MPSem->PrefsSem);
  270.           }//if(attemptsemshared()        
  271.         }//endelse (gotsem)
  272.         ReleaseScreen(Scr);
  273.       }
  274.       CleanupArgs();
  275.     }
  276.     CloseLibs(MP_Libs);
  277.   } 
  278.   if(LocaleBase)
  279.   {
  280.     CloseCatalog(Catalog);
  281.     CloseLibrary(LocaleBase);
  282.   }
  283. }
  284.  
  285.  
  286. void ProcessInput(void)
  287. {
  288.   struct IntuiMessage *imsg;
  289.   ULONG  winsig, signal, prefsig, allsigs,replysig;
  290.   
  291.   replysig= 1 << ReplyPort->mp_SigBit;
  292.   prefsig = 1 << PrefsPort->mp_SigBit; 
  293.   winsig  = 1 << Win->UserPort->mp_SigBit;  
  294.   allsigs = replysig | winsig | prefsig | SIGBREAKF_CTRL_C;
  295.   
  296.   while (!ClosePrefs)
  297.   {
  298.  
  299.     signal=Wait(allsigs);
  300.     
  301.     if(replysig & signal)
  302.     {
  303.       struct MPMessage *mpm;
  304.       while(mpm=(struct MPMessage *)GetMsg(ReplyPort))
  305.       {
  306.         //printf("Freeing Replied Msg %8x\n",mpm);
  307.         FreeVec(mpm);
  308.       }
  309.     }
  310.     
  311.     
  312.     if(SIGBREAKF_CTRL_C & signal)
  313.       ClosePrefs=TRUE;
  314.  
  315.     if(winsig & signal)
  316.     {
  317.       while(imsg = GT_GetIMsg(Win->UserPort))
  318.       {
  319.         switch (imsg->Class)
  320.         {
  321.           case IDCMP_MOUSEMOVE:
  322.             process_mousemoves(imsg);
  323.             break;
  324.           case IDCMP_GADGETUP:           
  325.             process_gadgetups(imsg);
  326.             break;
  327.             /*
  328.           case IDCMP_VANILLAKEY:
  329.             Process_Keys(imsg);
  330.             break;
  331.             */
  332. //          case IDCMP_CLOSEWINDOW:
  333. //            ClosePrefs=TRUE;
  334. //            break;
  335.           case IDCMP_REFRESHWINDOW:
  336.             GT_BeginRefresh(Win);
  337.             RefreshGUI();
  338.             GT_EndRefresh(Win,TRUE);
  339.             break;
  340.           case IDCMP_MENUPICK:
  341.             process_menus(imsg);
  342.             break;            
  343.         }
  344.         GT_ReplyIMsg(imsg);
  345.       }
  346.       {
  347.         struct DefaultNode *n;
  348.         
  349.         if(n=GetActiveNode())
  350.           switch(ActivateStrGad)
  351.           {
  352.             case GD_NAME:
  353.               if(CurrentList==PL_SCREENMODES)
  354.                 ActivateStrGad=0;
  355.             case GD_WIDTH:
  356.             case GD_HEIGHT:
  357.               if(n->ModeSelect!=MS_PROMOTE_SCREENMODE && n->ModeSelect!=MS_PROMOTE_REQUESTER)
  358.                 ActivateStrGad=0;
  359.               break;
  360.             case GD_PENVAL:
  361.               if(!n->Look3D)
  362.                 ActivateStrGad=0;
  363.               break;
  364.             case GD_LOCKEDPENS:
  365.               if(!(n->Flags & SHAREPENS))
  366.                 ActivateStrGad=0;
  367.               break;
  368.             case GD_PUBNAME:
  369.               if(n->PubOptions==0)
  370.                 ActivateStrGad=0;
  371.               break;
  372.             case GD_HOTKEYSTR:
  373.               if(!(n->Flags & SCRHOTKEY))
  374.                 ActivateStrGad=0;
  375.               break;
  376.           }
  377.       }
  378.       if(ActivateStrGad)
  379.       {
  380.         
  381.         ActivateGadget(gadlist[ActivateStrGad],Win,NULL);
  382.         ActivateStrGad=0;
  383.       }
  384.     }
  385.     
  386.     if(prefsig & signal)
  387.       ProcessPrefsMessages();
  388.   }
  389. }       
  390.  
  391. struct TextFont *GUIFont=0;
  392.  
  393.  
  394.  
  395. BOOL ShowGUI(void)
  396. {
  397.   static ULONG firsttime=2;
  398.   WORD WindowWidth=630,WindowHeight=204;  
  399.   WORD zoom[4];
  400.   ULONG skipbackdrop=2, skipgadgets=0;
  401.   
  402.   if(Win)
  403.   {
  404.     ActivateWindow(Win);
  405.     WindowToFront(Win);
  406.     ScreenToFront(Scr);
  407.     return(TRUE);
  408.   }
  409.       
  410.   if(VI=GetVisualInfo(Scr,TAG_END))
  411.   {
  412.     if(UserFontName)
  413.     {
  414.       User.ta_Name=UserFontName;
  415.       User.ta_YSize=UserFontSize;
  416.       User.ta_Style=0;
  417.       User.ta_Flags=0;
  418.       TAttr=&User;
  419.     }
  420.     else
  421.       TAttr=Scr->Font;
  422.     
  423.     GetGUIScale(TAttr,GText,&XScale,&YScale);
  424.     if(!CheckInnerWindowSize(Scr,WindowWidth,WindowHeight,XScale,YScale))
  425.     {
  426.       TAttr=&Topaz8;
  427.       XScale=1;
  428.       YScale=1;
  429.     }
  430.     if(GUIFont=OpenFont(TAttr))
  431.     {
  432.       SetupTextArea(&ColorDisp, GUIFont,   (MyScreen?0:Scr));
  433.       SetupTextArea(&PenNameDisp, GUIFont, (MyScreen?0:Scr));
  434.       SetupTextArea(&FontDisp, GUIFont, (MyScreen?0:Scr));
  435.       /*
  436.       ColorDisp_Left   *= XScale;
  437.       ColorDisp_Right  *= XScale;
  438.       ColorDisp_Top    *= YScale;
  439.       ColorDisp_Bottom *= YScale;
  440.       ColorDisp_Width =ColorDisp_Right-ColorDisp_Left;
  441.    
  442.       if(!MyScreen)
  443.       {
  444.         WORD wx,wy;
  445.         
  446.         wx=Scr->WBorLeft;
  447.         wy=Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  448.         ColorDisp_Left  +=wx;
  449.         ColorDisp_Top   +=wy;
  450.         ColorDisp_Right +=wx;
  451.         ColorDisp_Bottom+=wy;
  452.       }
  453.       ColorDisp_Baseline=(ColorDisp_Bottom-ColorDisp_Top-GUIFont->tf_YSize)/2 + GUIFont->tf_Baseline + ColorDisp_Top;
  454.       */
  455.           
  456.       if(glist=MakeGadgets((MyScreen?0:Scr),VI,Gadgets,nglist,gtags,gtype,gadlist,TAttr,XScale,YScale))
  457.       {
  458.         WindowWidth *=XScale;
  459.         WindowHeight*=YScale;
  460.         zoom[2]=160;
  461.         zoom[3]=Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  462.         if(V39)
  463.         {
  464.           zoom[0]=zoom[1]=~0;
  465.         }
  466.         else
  467.         {
  468.           zoom[0]=0;
  469.           zoom[1]=zoom[3];
  470.         }
  471.         if(MyScreen)
  472.         {
  473.           skipbackdrop=0;
  474.           skipgadgets=4;
  475.         }
  476.         if(Win=OpenWindowTags(NULL, 
  477.                             WA_InnerWidth   , WindowWidth,
  478.                             WA_InnerHeight  , WindowHeight,
  479.                             TAG_SKIP        , firsttime,
  480.                             WA_Left         , LeftEdge,
  481.                             WA_Top          , TopEdge,
  482.                             TAG_SKIP        , skipbackdrop,
  483.                             WA_Backdrop     , MyScreen,
  484.                             WA_Borderless   , TRUE,
  485.                             TAG_SKIP        , skipgadgets,
  486.                             WA_DragBar      , TRUE,
  487.                             WA_DepthGadget  , TRUE,
  488.                             WA_Zoom         , zoom,
  489.                             WA_Title        , WindowName ,
  490.                             WA_NewLookMenus , TRUE    ,
  491.                             WA_Gadgets      , glist   ,
  492.                             WA_AutoAdjust   , TRUE    ,
  493.                             WA_Activate     , TRUE    ,
  494.                             //WA_SmartRefresh , TRUE    ,
  495.                             WA_SimpleRefresh,  TRUE    ,
  496.                             WA_IDCMP        , MPP_IDCMP,
  497.                             WA_PubScreen  ,   Scr  ))
  498.         {
  499.           SetFont(Win->RPort,GUIFont);
  500.           FindMaxPenNameSize(TAttr);
  501.           GT_RefreshWindow(Win,0);
  502.           DrawBevelBoxes(Win,VI,BBox,BevelBoxes,XScale,YScale);
  503.           firsttime=0;
  504.           nm[4].nm_Flags =( nm[4].nm_Flags & ~CHECKED)|( MPSem->Enabled ? CHECKED:0);
  505.            if(V39)
  506.             nm[5].nm_Flags =( nm[5].nm_Flags & ~CHECKED)|(MPSem->EnabledNLM ? CHECKED:0);
  507.           else
  508.             nm[5].nm_Flags =((nm[5].nm_Flags | NM_ITEMDISABLED) & ~CHECKED);
  509.           nm[15].nm_Flags=(nm[15].nm_Flags & ~CHECKED)|(MPSem->CatchPrograms ? CHECKED:0);
  510.           nm[16].nm_Flags=(nm[16].nm_Flags & ~CHECKED)|(MPSem->CatchScreens ? CHECKED:0);
  511.           nm[18].nm_Flags=(nm[18].nm_Flags & ~CHECKED)|(MPSem->CatchPopup ? CHECKED:0);
  512.           nm[20].nm_Flags=(nm[20].nm_Flags & ~CHECKED)|(MPSem->Debug ? CHECKED:0);
  513.           if((MenuStrip=CreateMenus(nm,TAG_END))!=NULL)
  514.           {
  515.             if((LayoutMenus(MenuStrip,VI,
  516.                             GTMN_NewLookMenus,TRUE,
  517.                             TAG_END))!=NULL)
  518.             {          
  519.               if((SetMenuStrip(Win,MenuStrip))!=NULL)
  520.               {
  521.                 LVActive=0;
  522.                 
  523.                 GT_RefreshWindow(Win,NULL);
  524.                 UpdateGadgets();
  525.                 ScreenToFront(Scr);
  526.                 return(TRUE);
  527.               }
  528.             }
  529.           }
  530.         }
  531.       }
  532.     }
  533.   }
  534.   HideGUI();
  535.   return(FALSE);
  536. }
  537.  
  538.  
  539. void HideGUI()
  540. {
  541.   CleanUp();
  542.   if(Win)           
  543.   { 
  544.     ClearMenuStrip(Win);
  545.     LeftEdge=Win->LeftEdge;
  546.     TopEdge=Win->TopEdge;
  547.     CloseWindow(Win);    
  548.     
  549.     Win=0;
  550.   }
  551.   
  552.   if(GUIFont) CloseFont(GUIFont);
  553.   
  554.   /* These functions I KNOW are safe to call with a NULL */
  555.   FreeGadgets(glist);         glist=0;
  556.   FreeMenus(MenuStrip);       MenuStrip=0;
  557.   FreeVisualInfo(VI);         VI=0;
  558. }
  559.  
  560. struct Screen *GetScreen(void)
  561. {
  562.   struct Screen *gs;
  563.   WORD pens[]={~0};
  564.   ULONG dispid;
  565.   
  566.   MyScreen=FALSE;
  567.   
  568.   if(gs=LockPubScreen(ArgPubscreen))
  569.   {
  570.     if(gs->Height<217 || gs->Width<640)
  571.     {
  572.       MyScreen=TRUE;
  573.       dispid=GetVPModeID(&(gs->ViewPort));
  574.       UnlockPubScreen(0,gs);
  575.       gs=OpenScreenTags(0, SA_LikeWorkbench, TRUE,
  576.                            SA_Title        , ModePro,
  577.                            SA_DisplayID    , dispid,
  578.                            SA_Overscan     , OSCAN_TEXT,
  579.                            SA_AutoScroll   , TRUE,
  580.                            SA_Font         , &Topaz8,
  581.                            SA_Width        , 640,
  582.                            SA_Height       , 217,
  583.                            SA_Depth        ,   2,
  584.                            SA_Pens         , pens,
  585.                            TAG_DONE);
  586.     }
  587.   }
  588.   DrawInfo=GetScreenDrawInfo(gs);
  589.   return(gs);
  590. }
  591.  
  592. void ReleaseScreen(struct Screen *S)
  593. {
  594.   if(S)
  595.   {
  596.     FreeScreenDrawInfo(S,DrawInfo);
  597.     if(MyScreen)
  598.       CloseScreen(S);
  599.     else
  600.       UnlockPubScreen(0,S);
  601.   }
  602. }
  603.  
  604. void CleanUp(void)
  605. {
  606.   if(ScrReq)
  607.   {
  608.     FreeAslRequest(ScrReq);
  609.     ScrReq=0;
  610.   }
  611.   if(FileReq)
  612.   {
  613.     FreeAslRequest(FileReq);
  614.     FileReq=0;
  615.   }
  616.   if(FontReq)
  617.   {
  618.     FreeAslRequest(FontReq);
  619.     FontReq=0;
  620.   }
  621. }
  622.  
  623. void CheckMenuItem(ULONG MenuItem, BOOL Checked);
  624.  
  625. void ProcessPrefsMessages(void)
  626. {
  627.   ULONG listupd=FALSE;
  628.   struct MPMessage *mpm;
  629.  
  630. loopy:
  631.  
  632.   while(mpm=(struct MPMessage *)GetMsg(PrefsPort))
  633.   {
  634.     //printf("Recieved %8x - Command %d Code %d Data %8x\n",mpm,mpm->Command,mpm->Code,mpm->Data);   
  635.     switch(mpm->Command)
  636.     {
  637.       case MP_QUIT:
  638.       case MP_PREFSCLOSE:
  639.         ClosePrefs=TRUE;
  640.         break;
  641.       case MP_PREFSTOFRONT:
  642.         ScreenToFront(Scr);
  643.         WindowToFront(Win);
  644.         ActivateWindow(Win);
  645.         break;
  646.       case MP_LISTSTATUS:
  647.         switch(mpm->Code)
  648.         {
  649.           case MPLS_UPDATING:
  650.             listupd=TRUE;
  651.             GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  652.                          GTLV_Labels,~0,
  653.                          TAG_DONE);
  654.             
  655.             ReleaseSemaphore(&MPSem->ListSem);
  656.             break;
  657.           case MPLS_NORMAL:
  658.             listupd=FALSE;          
  659.             ObtainSemaphoreShared(&MPSem->ListSem);
  660.             LVActive=0;
  661.             UpdateGadgets();
  662.             break;
  663.         }
  664.         break;
  665.       case MP_REFRESH:
  666.       {
  667.         CheckMenuItem(M_ENABLED   ,MPSem->Enabled);
  668.         CheckMenuItem(M_ENABLENL  ,MPSem->EnabledNLM);  
  669.         CheckMenuItem(M_CATPROG   ,MPSem->CatchPrograms);
  670.         CheckMenuItem(M_CATSCR    ,MPSem->CatchScreens);
  671.         CheckMenuItem(M_CATPOP    ,MPSem->CatchPopup);
  672.         ResetMenuStrip(Win,MenuStrip);
  673.       }
  674.     }
  675.     ReplyMsg((struct Message *)mpm);
  676.   }
  677.   if(listupd)
  678.   {
  679.     WaitPort(PrefsPort);
  680.     goto loopy;
  681.   }
  682. }
  683.  
  684. void CheckMenuItem(ULONG MenuItem, BOOL Checked)
  685. {
  686.   struct MenuItem *mi;
  687.   
  688.   if(mi=ItemAddress(MenuStrip,MenuItem))
  689.   {
  690.     if(Checked)
  691.       mi->Flags|=CHECKED;
  692.     else
  693.       mi->Flags&=(~CHECKED);
  694.   }
  695. }
  696.     
  697. void process_gadgetups(struct IntuiMessage *imsg)
  698. {
  699.   struct Gadget *gad;
  700.   struct DefaultNode *n;
  701.   UWORD  code,id,l;  
  702.   
  703.   code=imsg->Code;
  704.   gad=(struct Gadget*)imsg->IAddress;
  705.   id=gad->GadgetID;  
  706.    
  707.   switch(id)
  708.   {
  709.     case GD_TYPE:
  710.       CurrentList_2=code;
  711.       CurrentList=ListToCyc[code];
  712.       LVActive=0;
  713.       UpdateGadgets();
  714.       break;
  715.  
  716.     case GD_NEW:
  717.       if(n=AllocDefaultNode(0))
  718.       {
  719.         if(CurrentList!=PL_SCREENMODES)
  720.           n->Def_Node.ln_Name=CopyString(MiscText[ITEM_NEW_NAME], MEMF_CLEAR | MEMF_PUBLIC);
  721.         else
  722.           n->Def_Node.ln_Name=GetModeName(0);
  723.         
  724.         n->Type=CurrentList;
  725.         n->OverscanType=1;
  726.         for(l=0;l<NumDriPens;l++)
  727.           n->Pens[l]=defaultpens[l];
  728.         
  729.         ObtainSemaphore(&MPSem->NodeSem);
  730.         GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  731.                          GTLV_Labels,~0,
  732.                          GTLV_Selected,0,TAG_DONE);
  733.         AddHead(&MPSem->PromotionList[CurrentList],(struct Node *)n);
  734.         LVActive=0;
  735.         
  736.         ReleaseSemaphore(&MPSem->NodeSem);
  737.         UpdateGadgets();
  738.         if(CurrentList!=PL_SCREENMODES)
  739.           ActivateStrGad=GD_NAME;
  740.       }
  741.       break;
  742.  
  743.     case GD_SAVE:
  744.       ClosePrefs=TRUE;
  745.       ObtainSemaphore(&MPSem->NodeSem);
  746.       PrefSaveFile(EnvArcFile);
  747.       PrefSaveFile(EnvFile);
  748.       ReleaseSemaphore(&MPSem->NodeSem);
  749.       break;
  750.     case GD_USE:
  751.       ClosePrefs=TRUE;
  752.       PrefSaveFile(EnvFile);
  753.       break;
  754.     case GD_CANCEL:
  755.       ObtainSemaphore(&MPSem->NodeSem);
  756.       GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  757.                         GTLV_Labels,~0,TAG_DONE);
  758.       FreeAllDefLists(MPSem->PromotionList);
  759.       PrefLoadFile(EnvFile);
  760.       ReleaseSemaphore(&MPSem->NodeSem);
  761.       ClosePrefs=TRUE;
  762.       break;
  763.   }
  764.  
  765.   if(n=GetActiveNode())  
  766.   switch(id)
  767.   {
  768.     case GD_LIST:
  769.       LVActive=code;
  770.       n=GetActiveNode();
  771.       GT_SetGadgetAttrs(gadlist[GD_MOVE],Win,NULL,
  772.                       GTSL_Max,       NodeCnt-1,
  773.                       GTSL_Level,    (NodeCnt-1)-LVActive,
  774.                       GA_Disabled,    FALSE,
  775.                       TAG_DONE);
  776.       //UpdateGadgets();
  777.       SetDispGadgets(n);
  778.       SetFontGadgets(n);
  779.       SetSharedGadgets(n);
  780.       SetPublicGadgets(n);
  781.       SetHotKeyGadgets(n);
  782.       SetOptionGadgets(n);
  783.       Set3DGadgets(n);
  784.       if(CurrentList!=PL_SCREENMODES)
  785.         ActivateStrGad=GD_NAME;
  786.       break;
  787.     case GD_SELECT_NAME:
  788.       GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  789.                            GTLV_Labels,~0,
  790.                            TAG_DONE);
  791.       SelectName(n);
  792.       GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  793.                            GTLV_Labels,&MPSem->PromotionList[CurrentList],
  794.                            TAG_DONE);
  795.       break;
  796.     case GD_NAME:
  797.       GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  798.                          GTLV_Labels,~0,TAG_DONE);
  799.       if(GetGadString(gadlist[GD_NAME]))
  800.       {
  801.         ObtainSemaphore(&MPSem->NodeSem);
  802.         FreeVec(n->Def_Node.ln_Name);
  803.         if(n->Def_Node.ln_Name=AllocVec( 1+strlen(GetGadString(gadlist[GD_NAME])),MEMF_CLEAR|MEMF_PUBLIC))
  804.           strcpy(n->Def_Node.ln_Name,GetGadString(gadlist[GD_NAME]));
  805.         else
  806.         {
  807.           Remove((struct Node *)n);
  808.           FreeDNode(n);
  809.           UpdateGadgets();
  810.         }
  811.         ReleaseSemaphore(&MPSem->NodeSem);
  812.       }
  813.      
  814.       GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  815.                          GTLV_Labels,&MPSem->PromotionList[CurrentList],
  816.                          TAG_DONE);
  817.  
  818.       break;
  819.       
  820.     case GD_MODESEL:
  821.       n->ModeSelect=code;
  822.       SetDispGadgets(n);
  823.       //UpdateGadgets();
  824.       break;
  825.  
  826.     case GD_SELMODE:
  827.       switch(n->ModeSelect)
  828.       {
  829.         case 1:
  830.           SelectScreenMode(Win,n,0);
  831.           break;
  832.         case 2:
  833.         case 3:
  834.           SelectScreenMode(Win,n,0);
  835.           break;
  836.       }
  837.       SetDispGadgets(n);
  838.       SetOptionGadgets(n);
  839.       break;
  840.  
  841.     case GD_WIDTH:
  842.       n->Width=GetGadNumber(gad);
  843.       break;
  844.  
  845.     case GD_HEIGHT:
  846.       n->Height=GetGadNumber(gad);
  847.       break;
  848.  
  849.     case GD_OVERSCAN:
  850.       n->OverscanType=code+1;
  851.       break;
  852.  
  853.     case GD_REMOVE:
  854.       ObtainSemaphore(&MPSem->NodeSem);
  855.       GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  856.                         GTLV_Labels,~0,TAG_DONE);
  857.       if(!(n->Def_Node.ln_Succ->ln_Succ))
  858.         if(LVActive>0)
  859.           LVActive--;
  860.       Remove((struct Node *)n);
  861.       FreeDNode(n);
  862.       ReleaseSemaphore(&MPSem->NodeSem);
  863.       CountNodes();
  864.       UpdateGadgets();
  865.       break;
  866.  
  867.     case GD_LOOK3D:
  868.       if(n->Look3D=gad->Flags & GFLG_SELECTED)
  869.         SetPenValues(n->Pens);
  870.       else
  871.         SetPenValues(0);
  872.       break;
  873.  
  874.     case GD_AUTOSCROLL:
  875.       n->AutoScroll=gad->Flags & GFLG_SELECTED;
  876.       break;
  877.  
  878.  
  879.     case GD_PENLIST:
  880.       ActivePen=code;
  881.       if(n->Look3D)
  882.       {
  883.         ActivateStrGad=GD_PENVAL;
  884.         SetPenValues(n->Pens);
  885.        // ActivateGadget(gadlist[GD_PENVAL],Win,NULL);
  886.       }
  887.       else
  888.         SetPenValues(0);
  889.       break;
  890.  
  891.     case GD_PENVAL:
  892.       n->Pens[ActivePen]=GetGadNumber(gadlist[GD_PENVAL]);
  893.       if(imsg->Qualifier&3)
  894.       {
  895.         ActivePen--;
  896.         if(ActivePen<0) ActivePen=NumDriPens-1;
  897.       }
  898.       else
  899.       {
  900.         ActivePen++;
  901.         if(ActivePen>=NumDriPens) ActivePen=0;
  902.       }
  903.       ActivateStrGad=GD_PENVAL;
  904.       SetPenValues(n->Pens);
  905.    //   ActivateGadget(gadlist[GD_PENVAL],Win,NULL);
  906.       break;
  907.  
  908.     case GD_RESETPENS:
  909.       ObtainSemaphore(&MPSem->NodeSem);
  910.       for(l=0;l<NumDriPens;l++)
  911.         n->Pens[l]=defaultpens[l];
  912.       ReleaseSemaphore(&MPSem->NodeSem);
  913.       SetPenValues(n->Pens);
  914.       break;
  915.  
  916.     case GD_PICKFONT:
  917.       if(PickFont(Win,&n->Font))
  918.       {
  919.         SetFontGadgets(n);
  920.       }
  921.       break;
  922.  
  923.     case GD_INTERLEAVE:
  924.       n->Flags&=(~INTERLEAVE);
  925.       if(gad->Flags & GFLG_SELECTED)
  926.         n->Flags|=INTERLEAVE;
  927.       break;
  928.       
  929.     case GD_CENTER:
  930.       n->CenterFlags=code;
  931.       break;
  932.  
  933.     case GD_FASPECT:
  934.       n->Flags&=(~FIXASPECT);
  935.       if(gad->Flags & GFLG_SELECTED)
  936.         n->Flags|=FIXASPECT;
  937.       break;
  938.  
  939.     case GD_SFONT:
  940.       n->FontType=code;
  941.       SetFontGadgets(n);
  942.       break;
  943.  
  944.     case GD_PUBOPT:
  945.       if(gad->Flags & GFLG_SELECTED)
  946.       {
  947.         n->PubOptions=1;
  948.         ActivateStrGad=GD_PUBNAME;
  949.       }
  950.       else
  951.         n->PubOptions=0;
  952.     
  953.       SetPublicGadgets(n);
  954.  
  955.       break;
  956.       
  957.     case GD_PUBNAME:
  958.       if(GetGadString(gadlist[GD_PUBNAME]))
  959.       {
  960.         ObtainSemaphore(&MPSem->NodeSem);
  961.         FreeVec(n->PubName);
  962.         if(n->PubName=AllocVec( 1+strlen(GetGadString(gadlist[GD_PUBNAME])),MEMF_CLEAR|MEMF_PUBLIC))
  963.           strcpy(n->PubName,GetGadString(gadlist[GD_PUBNAME]));
  964.         ReleaseSemaphore(&MPSem->NodeSem);
  965.       }      
  966.       break;
  967.       
  968.     case GD_DODEPTH:
  969.       n->Flags&=(~DEPTH);
  970.       if(gad->Flags & GFLG_SELECTED)
  971.         n->Flags|=DEPTH;
  972.       SetDepthGadgets(n);
  973.       break;
  974.       
  975.     case GD_SHAREPENS:
  976.       n->Flags&=(~SHAREPENS);
  977.       if(gad->Flags & GFLG_SELECTED)
  978.       {
  979.         n->Flags|=SHAREPENS;
  980.         ActivateStrGad=GD_LOCKEDPENS;
  981.       }
  982.       SetSharedGadgets(n);
  983.       break;
  984.       
  985.     case GD_LOCKEDPENS:
  986.       if(GetGadString(gadlist[GD_LOCKEDPENS]))
  987.       {
  988.         ObtainSemaphore(&MPSem->NodeSem);
  989.         FreeVec(n->LockedPens);
  990.         if(n->LockedPens=AllocVec( 1+strlen(GetGadString(gadlist[GD_LOCKEDPENS])),MEMF_CLEAR|MEMF_PUBLIC))
  991.           strcpy(n->LockedPens,GetGadString(gadlist[GD_LOCKEDPENS]));
  992.         ReleaseSemaphore(&MPSem->NodeSem);
  993.       }      
  994.       break;
  995.     
  996.     case GD_HOTKEYOPT:
  997.       n->Flags&=(~SCRHOTKEY);
  998.       if(gad->Flags & GFLG_SELECTED)
  999.       {
  1000.         n->Flags|=SCRHOTKEY;
  1001.         ActivateStrGad=GD_HOTKEYSTR;
  1002.       }
  1003.       SetHotKeyGadgets(n);
  1004.       break;
  1005.       
  1006.     case GD_HOTKEYSTR:
  1007.       if(GetGadString(gadlist[GD_HOTKEYSTR]))
  1008.       {
  1009.         ObtainSemaphore(&MPSem->NodeSem);
  1010.         FreeVec(n->HotKey);
  1011.         if(n->HotKey=AllocVec( 1+strlen(GetGadString(gadlist[GD_HOTKEYSTR])),MEMF_CLEAR|MEMF_PUBLIC))
  1012.           strcpy(n->HotKey,GetGadString(gadlist[GD_HOTKEYSTR]));
  1013.         ReleaseSemaphore(&MPSem->NodeSem);
  1014.       }
  1015.       break;
  1016.     case GD_PALETTE:
  1017.       n->Flags&=(~DNF_PALETTE);
  1018.       if(gad->Flags & GFLG_SELECTED)
  1019.         n->Flags|=DNF_PALETTE;
  1020.       SetPaletteGadgets(n);
  1021.       break;
  1022.     case GD_EDITPALETTE:
  1023.       PaletteReq(n);
  1024.       break;
  1025.   } /* End Switch */  
  1026. }
  1027.  
  1028. void Process_Keys(struct IntuiMessage *IMsg)
  1029. {
  1030.   ULONG code,gadid;
  1031.   WORD dirchange=1;
  1032.   
  1033.   code=IMsg->Code;
  1034.   
  1035.   gadid=KeyGad(code);
  1036.   
  1037.   if(shifted) dirchange=-1;
  1038.   
  1039.   switch(gadid)
  1040.   {
  1041.     case GD_NAME:
  1042.     case GD_WIDTH:
  1043.     case GD_HEIGHT:
  1044.     case GD_LOCKEDPENS:
  1045.     case GD_PUBNAME:
  1046.     case GD_HOTKEYSTR:
  1047.     case GD_PENVAL:
  1048.       ActivateStrGad=gadid;
  1049.       break;
  1050.     case GD_TYPE:
  1051.       CurrentList_2+=dirchange;
  1052.       GD_Type(CurrentList_2);
  1053.       break;
  1054.     case GD_NEW:
  1055.       GD_New();
  1056.       break;
  1057.     case GD_SAVE:
  1058.       GD_Save();
  1059.       break;
  1060.     case GD_USE:
  1061.       GD_Use();
  1062.       break;
  1063.     case GD_CANCEL:
  1064.       GD_Cancel();
  1065.       break;
  1066.     case GD_LIST:
  1067.       LVActive+=dirchange;
  1068.       if(LVActive>=NodeCnt)
  1069.         LVActive=0;
  1070.       GD_List(LVActive);
  1071.       break;
  1072.     case GD_SELECTNAME:
  1073.       GD_SelectName(n);
  1074.       break;
  1075.     case GD_MODESEL:
  1076.       GD_ModeSel(n,n->ModeSelect+dirchange);
  1077.       break;
  1078.     case GD_SELMODE:
  1079.       GD_SelMode(n);
  1080.       break;
  1081.     case GD_OVERSCAN: 
  1082.       GD_Overscan(n,n->OverscanType+dirchange-1,TRUE);
  1083.       break;
  1084.     case GD_REMOVE:
  1085.       GD_Remove(n);
  1086.       break;
  1087.     case GD_PENLIST:
  1088.       GD_PenList(n,ActivePen+dirchange);
  1089.       break;
  1090.     case GD_RESETPENS:
  1091.       GD_ResetPens(n);
  1092.       break;
  1093.     case GD_PICKFONT:
  1094.       GD_PickFont(n);
  1095.       break;
  1096.     case GD_INTERLEAVE:
  1097.       GD_Interleave(n,!(n->Flags & INTERLEAVE),TRUE);
  1098.       break;
  1099.     case GD_LOOK3D:
  1100.       GD_Look3D(n,!(n->Look3D));
  1101.       break;
  1102.     case GD_AUTOSCROLL:
  1103.       GD_AutoScroll(n,!(n->AutoScroll),TRUE);
  1104.       break;
  1105.     case GD_RESETPENS:
  1106.       GD_ResetPens(n);
  1107.       break;
  1108.     case GD_PICKFONT:
  1109.       GD_PickFont(n);
  1110.       break;
  1111.     case GD_CENTER:
  1112.       GD_Center(n,n->CenterFlags+dirchange);
  1113.       break;
  1114.     case GD_FASPECT:
  1115.       GD_FAspect(n,!(n->Flags & FIXASPECT),TRUE);
  1116.       break;
  1117.     case GD_SFONT:
  1118.       GD_SFont(n,n->FontType+dirchange);
  1119.       break;
  1120.     case GD_PUBOPT:
  1121.       GD_PubOpt(n,!(n->PubOptions));
  1122.       break;
  1123.     case GD_DODEPTH:
  1124.       GD_DoDepth(n,!(n->Flags & DEPTH));
  1125.       break;
  1126.     case GD_SHAREPENS:
  1127.       GD_SharePens(n,!(n->Flags & SHAREPENS));
  1128.       break;
  1129.     case GD_HOTKEYOPT:
  1130.       GD_HotKeyOpt(n,!(n->Flags & SCRHOTKEY));
  1131.       break;
  1132.     case GD_PALETTE:
  1133.       GD_Palette(n,!(n->Flags & DNF_PALETTE));
  1134.       break;
  1135.     case GD_EDITPALETTE:
  1136.       GD_EditPalette(n);
  1137.       break;
  1138.     case GD_MOVE:
  1139.       GD_Move(LVActive+dirchange);
  1140.       break;
  1141.     case GD_DEPTH:
  1142.       GD_Depth(n,n->Depth+dirchange,TRUE);
  1143.       break;
  1144.   }
  1145. }
  1146.  
  1147.   }
  1148. }
  1149.  
  1150.  
  1151. void process_mousemoves(struct IntuiMessage *imsg)
  1152. {
  1153.   struct Gadget *gad;
  1154.   struct DefaultNode *n,*wn;
  1155.   UWORD  code,id,uplist=FALSE;  
  1156.   
  1157.   code=imsg->Code;
  1158.   gad=(struct Gadget*)imsg->IAddress;
  1159.   id=gad->GadgetID;
  1160.   if(n=GetActiveNode())
  1161.   {
  1162.     switch(id)
  1163.     {
  1164.       case GD_MOVE:
  1165.         ObtainSemaphore(&MPSem->NodeSem);
  1166.         code=(NodeCnt-1)-code;
  1167.         if(code<LVActive) uplist=TRUE;
  1168.         LVActive=code;
  1169.         if(wn=GetActiveNode())
  1170.         if(uplist) wn=(struct DefaultNode *)wn->Def_Node.ln_Pred;
  1171.           if(wn!=n)
  1172.           {
  1173.             GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  1174.                          GTLV_Labels,~0,
  1175.                          TAG_DONE);
  1176.             Remove((struct Node *)n);
  1177.             Insert(&MPSem->PromotionList[CurrentList],(struct Node *)n,(struct Node *)wn);
  1178.             GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  1179.                          GTLV_Labels,&MPSem->PromotionList[CurrentList],
  1180.                          GTLV_MakeVisible,LVActive,
  1181.                          GTLV_Selected,LVActive,TAG_DONE);
  1182.  
  1183.           }  
  1184.         ReleaseSemaphore(&MPSem->NodeSem); 
  1185.         break;
  1186.       case GD_DEPTH:
  1187.         n->Depth=code;
  1188.         WriteColorDisp(n);
  1189.         break;
  1190.     } /* End Switch */
  1191.   }  
  1192. }
  1193.  
  1194.  
  1195. void process_menus(struct IntuiMessage *imsg)
  1196. {
  1197.   UWORD  menunumber,ns;
  1198.   ULONG  menuid;
  1199.   struct MenuItem *mi;
  1200.   
  1201.   menunumber=imsg->Code;
  1202.   mi=ItemAddress(MenuStrip,menunumber);
  1203.   if(mi)
  1204.   do
  1205.   {
  1206.     menuid=(ULONG)(GTMENUITEM_USERDATA(mi));
  1207.     switch(menuid)
  1208.     {
  1209.       case M_OPEN:
  1210.         if(SelectFile(MiscText[LOAD_MP_PREFS],FALSE) )
  1211.         {
  1212.            ObtainSemaphore(&MPSem->NodeSem);
  1213.            GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  1214.                          GTLV_Labels,~0,TAG_DONE);
  1215.            FreeAllDefLists(MPSem->PromotionList);
  1216.            ReleaseSemaphore(&MPSem->NodeSem);
  1217.            PrefLoadFile(filename);
  1218.  
  1219. //           GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  1220. //                         GTLV_Labels,&MPSem->PromotionList[CurrentList],GTLV_Selected,0,TAG_DONE);
  1221.            LVActive=0;
  1222.            UpdateGadgets();
  1223.         }
  1224.         break;
  1225.         /*
  1226.       case M_SAVE:
  1227.         ObtainSemaphore(&MPSem->NodeSem);
  1228.         PrefSaveFile(EnvArcFile);
  1229.         PrefSaveFile(EnvFile);
  1230.         ReleaseSemaphore(&MPSem->NodeSem);
  1231.         break;
  1232.         */
  1233.       case M_SAVEAS:
  1234.         if(SelectFile(MiscText[SAVE_MP_PREFS],TRUE) )
  1235.         {
  1236.           PrefSaveFile(filename);     
  1237.         }
  1238.         break;
  1239.       case M_ENABLED:
  1240.         MPSem->Enabled=(mi->Flags & CHECKED ? 1:0);
  1241.         //ActivateCxObj(Broker,MPSem->Enabled);
  1242.         break;
  1243.       case M_ABOUT:
  1244.         {
  1245.           EZReq(0,0,ModePro,AboutText,MiscText[OK],(ULONG)GetString(MSG_ABOUT_TRANSLATOR),
  1246.                                                     (ULONG)GetString(MSG_ABOUT_FORINFO));
  1247.         }
  1248.         break;
  1249.       case M_HIDE:
  1250.         ClosePrefs=TRUE;
  1251.         //PrefSaveFile(EnvFile);
  1252.         break;
  1253.       case M_LASTSAVED:
  1254.         ObtainSemaphore(&MPSem->NodeSem);
  1255.         GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  1256.                                  GTLV_Labels,~0,TAG_DONE);
  1257.         FreeAllDefLists(MPSem->PromotionList);
  1258.         ReleaseSemaphore(&MPSem->NodeSem);
  1259.         PrefLoadFile(EnvArcFile);
  1260. //        GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  1261.   //                      GTLV_Labels,&MPSem->PromotionList[CurrentList],GTLV_Selected,0,TAG_DONE);
  1262.         LVActive=0;
  1263.         UpdateGadgets();
  1264.         break;   
  1265.       case M_RESTORE:
  1266.         ObtainSemaphore(&MPSem->NodeSem);
  1267.         GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  1268.                                  GTLV_Labels,~0,TAG_DONE);
  1269.         FreeAllDefLists(MPSem->PromotionList);
  1270.         ReleaseSemaphore(&MPSem->NodeSem);
  1271.         PrefLoadFile(EnvFile);
  1272. //        GT_SetGadgetAttrs(gadlist[GD_LIST],Win,NULL,
  1273.   //                      GTLV_Labels,&MPSem->PromotionList[CurrentList],GTLV_Selected,0,TAG_DONE);
  1274.         LVActive=0;
  1275.         UpdateGadgets();
  1276.         break;   
  1277.       case M_QUIT:
  1278.         SendDaemonMsg(MP_QUIT,0,0);
  1279.         break;
  1280.       case M_CATPROG:
  1281.         MPSem->CatchPrograms=(mi->Flags & CHECKED ? 1:0);
  1282.         break;
  1283.       case M_CATSCR:
  1284.         MPSem->CatchScreens=(mi->Flags & CHECKED ? 1:0);
  1285.         break;
  1286.       case M_CATPOP:
  1287.         MPSem->CatchPopup=(mi->Flags & CHECKED ? 1:0);
  1288.         break;
  1289.       case M_ENABLENL:
  1290.         MPSem->EnabledNLM=(mi->Flags & CHECKED ? 1:0);
  1291.         break;
  1292.       case M_DEBUG:
  1293.         MPSem->Debug=(mi->Flags & CHECKED ? 1:0);
  1294.     }
  1295.     ns=mi->NextSelect;
  1296.     mi=ItemAddress(MenuStrip,mi->NextSelect);
  1297.   }while(ns!= MENUNULL && mi);
  1298. }
  1299.  
  1300. void SetupPenNodes(void)
  1301. {
  1302.   ULONG pen;
  1303.   
  1304.   NewList(&PenList);
  1305.   for(pen=0;pen<NumDriPens;pen++)
  1306.   {
  1307.     pennode[pen].PenNumber       =PenNumbers[pen];
  1308.     pennode[pen].Pen_Node.ln_Name=PenNames[pen];
  1309.     pennode[pen].Pen_Node.ln_Succ=pennode[pen].Pen_Node.ln_Pred=0;
  1310.     AddTail(&PenList,(struct Node *)&pennode[pen]);
  1311.   }  
  1312. }
  1313.  
  1314. void SetPenValues(WORD *pens)
  1315. {
  1316.   ULONG pen,maxlenpng;
  1317.  
  1318.  
  1319.   GT_SetGadgetAttrs(gadlist[GD_PENLIST],Win,NULL,
  1320.                     GTLV_Labels,~0,TAG_DONE);  
  1321.   if(pens)
  1322.   {
  1323.     for(pen=0;pen<NumDriPens;pen++)
  1324.     {
  1325.       stci_d(&PenNames[pen][PenNameLength[pen]],pens[pen]);
  1326.     }
  1327.     
  1328.     GT_SetGadgetAttrs(gadlist[GD_PENVAL],Win,NULL,
  1329.                          GA_Disabled  ,FALSE,
  1330.                          GTIN_Number  ,pens[ActivePen],
  1331.                          TAG_DONE);
  1332.     GT_SetGadgetAttrs(gadlist[GD_RESETPENS],Win,NULL,
  1333.                          GA_Disabled  ,FALSE,
  1334.                          TAG_DONE);
  1335.   }
  1336.   else
  1337.   {
  1338.     for(pen=0;pen<NumDriPens;pen++)
  1339.     {
  1340.       PenNames[pen][PenNameLength[pen]]=0;
  1341.     }
  1342.     GT_SetGadgetAttrs(gadlist[GD_PENVAL],Win,NULL,
  1343.                          GA_Disabled  ,TRUE,
  1344.                          TAG_DONE);
  1345.     GT_SetGadgetAttrs(gadlist[GD_RESETPENS],Win,NULL,
  1346.                          GA_Disabled  ,TRUE,
  1347.                          TAG_DONE);
  1348.  
  1349.   }
  1350.   GT_SetGadgetAttrs(gadlist[GD_PENLIST],Win,NULL,
  1351.                          GTLV_Labels      ,&PenList,
  1352.                          GTLV_MakeVisible ,ActivePen,
  1353.                          GTLV_Selected    ,ActivePen,
  1354.                          GA_Disabled      ,!pens,
  1355.                          TAG_DONE);
  1356.   //GT_SetGadgetAttrs(gadlist[GD_PENNAME],Win,NULL,
  1357.   //                       GTTX_Text,NULL,TAG_DONE);
  1358.   
  1359.   
  1360.   maxlenpng=min(31,PenNameLength[ActivePen]);
  1361.   strncpy(PenNameGad,PenNames[ActivePen],maxlenpng);
  1362.   PenNameGad[maxlenpng]=0;
  1363.   //GT_SetGadgetAttrs(gadlist[GD_PENNAME],Win,NULL,
  1364.   //                       GTTX_Text,PenNameGad,TAG_DONE);
  1365.   WritePenNameDisp(PenNameGad);
  1366. }    
  1367.  
  1368. LONG SendDaemonMsg(ULONG Command, ULONG Code, APTR Data)
  1369. {
  1370.   LONG rv=0;
  1371.   struct MPMessage *mpm;
  1372.  
  1373.   if(mpm=AllocVec(sizeof(struct MPMessage),MEMF_PUBLIC|MEMF_CLEAR))
  1374.   {
  1375.     mpm->Command=Command;
  1376.     mpm->Code=Code;
  1377.     mpm->Data=Data;
  1378.     mpm->mp_Message.mn_ReplyPort=ReplyPort;
  1379.  
  1380.     //printf("Sending  %8x - Command %d Code %d Data %8x\n",mpm,mpm->Command,mpm->Code,mpm->Data);   
  1381.     PutMsg(MPSem->DaemonPort,(struct Message *)mpm);
  1382.     rv=1;
  1383.   }
  1384.  
  1385.   return(rv);
  1386. }
  1387.  
  1388. BOOL PrefLoadFile(STRPTR FileName)
  1389. {
  1390.   LONG error;
  1391.   BOOL rv;
  1392.   
  1393.   ObtainSemaphore(&MPSem->NodeSem);
  1394.   rv=LoadFile(MPSem->PromotionList,FileName);
  1395.   ReleaseSemaphore(&MPSem->NodeSem);
  1396.   if(error=IoErr())
  1397.   {
  1398.     UBYTE errstr[91];
  1399.  
  1400.     Fault(error,MiscText[LOAD_ERROR],errstr,90);
  1401.     EZReq(0,0,ModePro,errstr,MiscText[OK],0);
  1402.   }
  1403.   return(rv);
  1404. }    
  1405.  
  1406.  
  1407. BOOL PrefSaveFile(STRPTR FileName)
  1408. {
  1409.   LONG error;
  1410.   BOOL rv;
  1411.   
  1412.   ObtainSemaphore(&MPSem->NodeSem);
  1413.   rv=SaveFile(MPSem->PromotionList,FileName);
  1414.   ReleaseSemaphore(&MPSem->NodeSem);
  1415.  
  1416.   if(error=IoErr())
  1417.   {
  1418.     UBYTE errstr[91];
  1419.  
  1420.     Fault(error,MiscText[SAVE_ERROR],errstr,90);
  1421.     EZReq(0,0,ModePro,errstr,MiscText[OK],0);
  1422.   }
  1423.   return(rv);
  1424. }    
  1425.  
  1426. void FixScreenModeNames(void)
  1427. {
  1428.   struct DefaultNode *dn;
  1429.   STRPTR newname;
  1430.  
  1431.   ObtainSemaphore(&MPSem->NodeSem);
  1432.   dn=(struct DefaultNode *)MPSem->PromotionList[PL_SCREENMODES].lh_Head;
  1433.   while(dn->Def_Node.ln_Succ)
  1434.   {
  1435.     if(newname=GetModeName(dn->OrigDisplayID))
  1436.     {
  1437.       FreeVec(dn->Def_Node.ln_Name);
  1438.       dn->Def_Node.ln_Name=newname;
  1439.     }
  1440.     dn=(struct DefaultNode *)dn->Def_Node.ln_Succ;
  1441.   }
  1442.   ReleaseSemaphore(&MPSem->NodeSem);
  1443. }
  1444.  
  1445. void SetupTextArea(struct TextArea *TA, struct TextFont *Font, struct Screen *Screen)
  1446. {
  1447.   TA->LeftEdge   *= XScale;
  1448.   TA->RightEdge  *= XScale;
  1449.   TA->TopEdge    *= YScale;
  1450.   TA->BottomEdge *= YScale;
  1451.   TA->Width       = TA->RightEdge  - TA->LeftEdge;
  1452.   TA->Height      = TA->BottomEdge - TA->TopEdge;
  1453.   if(Screen)
  1454.   {
  1455.     WORD wx,wy;
  1456.     
  1457.     wx=Screen->WBorLeft;
  1458.     wy=Screen->WBorTop + Screen->RastPort.TxHeight + 1;
  1459.     TA->LeftEdge  +=wx;
  1460.     TA->TopEdge   +=wy;
  1461.     TA->RightEdge +=wx;
  1462.     TA->BottomEdge+=wy;
  1463.   }
  1464.   TA->Baseline=(TA->BottomEdge - TA->TopEdge - Font->tf_YSize)/2 
  1465.                       + Font->tf_Baseline + TA->TopEdge;
  1466. }
  1467.